<template>
	<view class="address_container">
		<view class="address_info display space-between align-items" v-for="(item,index) in addressList" :key="index">
			<view class="address_info_left">
				<view class="address_info_ls_top display align-items">
					<view class="default" v-if="item.is_default==1">默认</view>
					<view class="name">{{item.consignee}}</view>
					<view class="phone">{{item.mobile}}</view>
				</view>
				<view class="address_info_ls_bottom">{{item.province_name}}-{{item.city_name}}-{{item.county_name}}-{{item.address}}</view>
			</view>
			<view class="address_info_right" @click="goaddAddress(item.id)">
				<image class="address_info_right_icon" src="../../../static/icon/edit.png"></image>
			</view>
		</view>
		<view class="no_thing" v-if="addressList.length==0">
			<image src="../../../static/icon/no_address.png"></image>
			<view class="no_thing_text">暂无内容</view>
		</view>
		<view class="btn display align-items space-center letter-spacing" @click="goaddAddress(0)">新增地址</view>
		<is-login v-on:childClick='listenToClose' v-on:childClickAgain='listenToCloseAgain' v-if="isLogin==0"></is-login>
	</view>
</template>

<script>
	import isLogin from '../../../components/isLogin.vue'
	export default {
		data() {
			return {
				addressList: [],
				isLogin: 1
			}
		},
		components: {
			isLogin,
		},
		onLoad() {
			if (!uni.getStorageSync('openid')) {
				this.isLogin = 0
			} else {
				this.getCartNum()
			}
		},
		onShow() {
			this.getCartNum()
		},
		onPullDownRefresh() {
			uni.showToast({
				icon: 'loading',
				title: '加载中',
			});
			setTimeout(() => {
				this.getCartNum(() => {
					uni.hideLoading()
					uni.stopPullDownRefresh()
				})
			}, 1000)
		},
		methods: {
			// 获取地址数据
			getCartNum(callback) {
				let that = this
				var data = {
					openid: uni.getStorageSync('openid')
				}
				this.$myRequest.post(this.$api.address.getAddressListUrl, data).then(res => {
					if (res.code == '200') {
						that.addressList = res.data.data
						callback && callback()
					} else {
						uni.showToast({
							title: res.msg,
							icon: "none"
						})
					}
				})
			},
			goaddAddress(id) {
				if (!id) {
					uni.navigateTo({
						url: "./addAddress?id=0"
					})
				} else {
					uni.navigateTo({
						url: "./addAddress?id=" + id
					})
				}
			},
			listenToClose(msg) {
				this.isLogin = msg
			},
			listenToCloseAgain() {
				this.getCartNum()
			},
		}
	}
</script>

<style lang="scss" scoped>
	.address_container {
		width: 690rpx;
		margin: auto;

		.address_info {
			padding: 25rpx 0 20rpx 0;
			border-bottom: 1px solid #E5E5E5;

			.address_info_left {
				width: 640rpx;
				.address_info_ls_top {
					font-size: 26rpx;

					.default {
						width: 50rpx;
						height: 26rpx;
						background: #EEF5FF;
						border: 1px solid #7F99BB;
						border-radius: 4rpx;
						color: #7F99BB;
						font-size: 19rpx;
						text-align: center;
						line-height: 26rpx;
						margin-right: 20rpx;
					}

					.name {}

					.phone {
						margin-left: 25rpx;
					}
				}

				.address_info_ls_bottom {
					font-size: 26rpx;
					margin-top: 8rpx;
				}
			}

			.address_info_right {
				width: 32rpx;
				height: 32rpx;

				.address_info_right_icon {
					width: 100%;
					height: 100%;
				}
			}

		}
	}
</style>
